package com.jd.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.jd.model.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;

import com.jd.service.RoleResourceUserService;
import com.jd.entity.RoleResourceUser;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户权限配置 前端控制器
 * </p>
 *
 * @author wangshuping
 * @since 2021-11-21
 */
@RestController
@Api(tags = "RoleResourceUser接口管理")
@RequestMapping("/role-resource-user")
public class RoleResourceUserController {

    @Autowired
    public RoleResourceUserService roleResourceUserService;

    @GetMapping()
    @ApiOperation("获取列表")
    public Response list() throws Exception {
        return Response.ok(roleResourceUserService.list());
    }

    @GetMapping("/{key}")
    @ApiOperation("根据key获取")
    public Response getByKey(@PathVariable String key) throws Exception {
        return Response.ok(roleResourceUserService.getById(key));
    }

    @PostMapping
    @ApiOperation("保存")
    public Response save(@RequestBody RoleResourceUser roleResourceUser) throws Exception {
        boolean b = roleResourceUserService.save(roleResourceUser);
        return b ? Response.ok() : Response.fail();
    }

    @PutMapping
    @ApiOperation("修改")
    public Response update(@RequestBody RoleResourceUser roleResourceUser) throws Exception {
        boolean b = roleResourceUserService.updateById(roleResourceUser);
        return b ? Response.ok() : Response.fail();
    }

    @DeleteMapping("/{keys}")
    @ApiOperation("根据key值删除")
    public Response deleteByKeys(@PathVariable String[] keys) throws Exception {
        boolean b = roleResourceUserService.removeByIds(Arrays.asList(keys));
        return b ? Response.ok() : Response.fail();
    }
}
